package mmc.resource.models.collada;

import java.util.List;

public class Matrix4 {
		
	float[] m = new float[16];
	
	public Matrix4(){
		m = new float[]{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
	}
	
	public Matrix4(List<Double> ld){
		for(int i=0;i<16;i++)
			m[i] = (float)(double)ld.get(i);
	}
	
	public void setMult(Matrix4 m1, Matrix4 m2){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				int idx = i*3+j;
				m[idx] = 0;
				for(int k=0;k<3;k++){
					m[idx] += m1.m[i*3+k]*m2.m[k*3+j];
				}
			}
		}
	}
	
	public void multVect(float xin, float yin, float zin, float[] out, int outOffset){
		outOffset *= 3;
		float w = m[12]*xin + m[13]*yin + m[14]*zin + m[15]; 
		
		out[outOffset++] = (m[0]*xin + m[1]*yin + m[2]*zin + m[3]) / w;
		out[outOffset++] = (m[4]*xin + m[5]*yin + m[6]*zin + m[4]) / w;
		out[outOffset++] = (m[8]*xin + m[9]*yin + m[10]*zin + m[11]) / w;
	}
}
